home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 11 / Mac Magazin and MacEasy Magazine CD - Issue 11.iso / Sharewarebibliothek / Entwickler / WASTE 1.1 C / WEDebug.c < prev    next >
Text File  |  1995-02-13  |  3KB  |  87 lines

  1. // { WASTE PROJECT }
  2. // { Debugging Routines }
  3.  
  4. // { Copyright © 1993-1994 Marco Piovanelli }
  5. // { All Rights Reserved }
  6.  
  7. #include "WASTEIntf.h"
  8.  
  9. #ifdef WASTE_DEBUG
  10. pascal void _WEAssert(Boolean condition, StringPtr message)
  11. {
  12.     if (condition == false)
  13.     {
  14. //                message := Concat('Assertion Failed: ', message);
  15.         DebugStr(message);
  16.     }
  17. } // { _WEAssert }
  18.  
  19. pascal void _WESanityCheck(WEHandle hWE)
  20. {
  21.     // { _WESanityCheck performs several checks on two key data structures: }
  22.     // { the run array and the style table, verifying a number of assertions. }
  23.     // { This routine made it possible to identify many subtle bugs during development. }
  24.  
  25.     WEPtr pWE;
  26.     RunArrayPtr    pRuns;
  27.     StyleTablePtr pStyles;
  28.     long i, j, refCount;
  29.  
  30.     // { we aren't going to move memory }
  31.     pWE = *hWE;
  32.     pRuns = *(pWE->hRuns);
  33.     pStyles = *(pWE->hStyles);
  34.  
  35.     // { check the consistency of the run array }
  36.     // { first runStart must be zero }
  37.     _WEAssert(pRuns[0].runStart == 0, "\pFirst run array element is bad");
  38.  
  39.     // { last (dummy) runStart must be textLength + 1 and styleIndex must be -1 }
  40.     _WEAssert((pRuns[pWE->nRuns].runStart == pWE->textLength + 1) && 
  41.         (pRuns[pWE->nRuns].styleIndex == -1), "\pLast run array element is bad");
  42.  
  43.     // { all runs must be at least one character long }
  44.     for (i = pWE->nRuns - 1; i>=0; i--)
  45.         _WEAssert(pRuns[i + 1].runStart - pRuns[i].runStart > 0, "\pRun length less than one");
  46.  
  47.     // { no two consecutive runs may reference the same style }
  48.     for (i = pWE->nRuns - 1; i>=0; i--)
  49.         _WEAssert(pRuns[i + 1].styleIndex != pRuns[i].styleIndex, "\pSpurious run boundary");
  50.  
  51.     // { all run array elements (except the last dummy entry) must reference an existing style }
  52.     j = pWE->nStyles;
  53.     for (i = pWE->nRuns - 1; i>=0; i--)
  54.         _WEAssert((pRuns[i].styleIndex >= 0) && (pRuns[i].styleIndex < j),
  55.              "\pInvalid style index");
  56.  
  57.     // { the number of runs referencing each style in the style table }
  58.     // { must match the style reference count }
  59.     for (j = pWE->nStyles - 1; j>=0; j--)
  60.     {
  61.         refCount = 0;
  62.         for (i = pWE->nRuns - 1; i>=0; i--)
  63.         {
  64.             if (pRuns[i].styleIndex == j)
  65.                     refCount = refCount + 1;
  66.         }
  67.         _WEAssert(pStyles[j].refCount == refCount, "\pBad style reference count");
  68.     }
  69.  
  70. /* the following code crashes for some reason -- Dan Crevier 2/13/95
  71.     // { there may not be two identical entries in the style table (except for unused entries) }
  72.     for (i = pWE->nStyles - 1; i>0; i--)
  73.     {
  74.         if (pStyles[i].refCount == 0)
  75.             continue;
  76.         for (j = i - 1; j>=0; j--)
  77.         {
  78.             if (pStyles[j].refCount == 0)
  79.                 continue;
  80.             _WEAssert(_WEBlockCmp((Ptr)&pStyles[i].info, (Ptr)&pStyles[j].info,
  81.                 sizeof(pStyles[i].info)) == false, "\pDuplicate entry in style table");
  82.         }
  83.     }
  84. */
  85. } // { _WESanityCheck }
  86.  
  87. #endif